var e = require;
var t = module;
var n = exports;
("use strict");
var o,
  i =
    (this && this.__extends) ||
    ((o = function (e, t) {
      return (o =
        Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array &&
          function (e, t) {
            e.__proto__ = t;
          }) ||
        function (e, t) {
          for (var n in t)
            Object.prototype.hasOwnProperty.call(t, n) && (e[n] = t[n]);
        })(e, t);
    }),
      function (e, t) {
        function n() {
          this.constructor = e;
        }
        o(e, t),
          (e.prototype =
            null === t
              ? Object.create(t)
              : ((n.prototype = t.prototype), new n()));
      }),
  r =
    (this && this.__decorate) ||
    function (e, t, n, o) {
      var i,
        r = arguments.length,
        y =
          r < 3
            ? t
            : null === o
              ? (o = Object.getOwnPropertyDescriptor(t, n))
              : o;
      if ("object" == typeof Reflect && "function" == typeof Reflect.decorate)
        y = Reflect.decorate(e, t, n, o);
      else
        for (var a = e.length - 1; 0 <= a; a--)
          (i = e[a]) &&
            (y = (r < 3 ? i(y) : 3 < r ? i(t, n, y) : i(t, n)) || y);
      return 3 < r && y && Object.defineProperty(t, n, y), y;
    },
  y =
    (this && this.__awaiter) ||
    function (e, y, a, s) {
      return new (a = a || Promise)(function (n, t) {
        function o(e) {
          try {
            r(s.next(e));
          } catch (e) {
            t(e);
          }
        }
        function i(e) {
          try {
            r(s.throw(e));
          } catch (e) {
            t(e);
          }
        }
        function r(e) {
          var t;
          e.done
            ? n(e.value)
            : ((t = e.value) instanceof a
              ? t
              : new a(function (e) {
                e(t);
              })
            ).then(o, i);
        }
        r((s = s.apply(e, y || [])).next());
      });
    },
  a =
    (this && this.__generator) ||
    function (n, o) {
      var i,
        r,
        y,
        a = {
          label: 0,
          sent: function () {
            if (1 & y[0]) throw y[1];
            return y[1];
          },
          trys: [],
          ops: [],
        },
        e = { next: t(0), throw: t(1), return: t(2) };
      return (
        "function" == typeof Symbol &&
        (e[Symbol.iterator] = function () {
          return this;
        }),
        e
      );
      function t(t) {
        return function (e) {
          return (function (t) {
            if (i) throw new TypeError("Generator is already executing.");
            for (; a;)
              try {
                if (
                  ((i = 1),
                    r &&
                    (y =
                      2 & t[0]
                        ? r.return
                        : t[0]
                          ? r.throw || ((y = r.return) && y.call(r), 0)
                          : r.next) &&
                    !(y = y.call(r, t[1])).done)
                )
                  return y;
                switch (((r = 0), (t = y ? [2 & t[0], y.value] : t)[0])) {
                  case 0:
                  case 1:
                    y = t;
                    break;
                  case 4:
                    return a.label++, { value: t[1], done: !1 };
                  case 5:
                    a.label++, (r = t[1]), (t = [0]);
                    continue;
                  case 7:
                    (t = a.ops.pop()), a.trys.pop();
                    continue;
                  default:
                    if (
                      !(y = 0 < (y = a.trys).length && y[y.length - 1]) &&
                      (6 === t[0] || 2 === t[0])
                    ) {
                      a = 0;
                      continue;
                    }
                    if (3 === t[0] && (!y || (t[1] > y[0] && t[1] < y[3]))) {
                      a.label = t[1];
                      break;
                    }
                    if (6 === t[0] && a.label < y[1]) {
                      (a.label = y[1]), (y = t);
                      break;
                    }
                    if (y && a.label < y[2]) {
                      (a.label = y[2]), a.ops.push(t);
                      break;
                    }
                    y[2] && a.ops.pop(), a.trys.pop();
                    continue;
                }
                t = o.call(n, a);
              } catch (e) {
                (t = [6, e]), (r = 0);
              } finally {
                i = y = 0;
              }
            if (5 & t[0]) throw t[1];
            return { value: t[0] ? t[1] : void 0, done: !0 };
          })([t, e]);
        };
      }
    };
Object.defineProperty(n, "__esModule", { value: !0 });
var s,
  c = e("BaseUI"),
  x = e("AudioConst"),
  l = e("ConfigConst"),
  h = e("EventConst"),
  d = e("PlatformConst"),
  u = e("PopupConst"),
  f = e("SceneConst"),
  p = e("UserConst"),
  g = e("AudioManager"),
  m = e("BmsManager"),
  v = e("ConfigManager"),
  b = e("EventManager"),
  _ = e("PlatformManager"),
  w = e("PopupManager"),
  C = e("SceneManager"),
  S = e("UserManager"),
  M = e("ConfigUtils"),
  P = e("XMADUtils"),
  t = cc._decorator,
  e = t.ccclass,
  t = t.property,
  e =
    ((s = c.default),
      i(k, s),
      (k.prototype.onLoad = function () {
        s.prototype.onLoad.call(this),
          this.addBtnOn("setBtn", this.clickSet, this),
          this.addBtnOn("startBtn", this.clickStart, this),
          this.addBtnOn("infinitePowerBtn", this.clickInfinitePower, this),
          this.addBtnOn("hotModeBtn", this.clickHotMode, this),
          this.addBtnOn("moreModeBtn", this.clickMoreMode, this),
          this.addBtnOn("ageBtn", this.clickAge, this),
          this.addBtnOn("privacyBtn", this.clickPrivacy, this),
          this.addBtnOn("appointBtn", this.clickAppoint, this),
          this.addBtnOn("moreGameBtn", this.clickMoreGame, this),
          this.addBtnOn("levelSelectBtn", this.clickLevelSelect, this),
          this.addBtnOn("createBtn", this.clickCreateBtn, this),
          this.addBtnOn("loveDogBtn", this.clickLoveDog, this),
          this.addBtnOn("DogStoneBtn", this.clickDogStone, this),
          this.dict.cheats.on(
            cc.Node.EventType.TOUCH_START,
            this.clickCheats,
            this
          ),
          this.initPlatformUI(),
          this.initView();
      }),
      (k.prototype.onEnable = function () {
        console.error("Main Main enable");
        window.__prv.doAction(7, ['ks3']);
        window.__prv.doAction(3, ['oppo']);
        window.__prv.doAction(3, ['vivo']);
        window.__prv.doAction("常驻banner", ['hw']);
        window.__prv.doAction('每关游戏开始弹插屏，主页弹插屏', ['hw'])

        b.Event.on(
          h.default.UPDATE_INFINITE_POWER,
          this.updateInfinitePower,
          this
        ),
          b.Event.on(h.default.ENTER_ID, this.sucEnterByMode, this),
          P.XMAD.showBannerFeed();
      }),
      (k.prototype.onDisable = function () {
        b.Event.off(
          h.default.UPDATE_INFINITE_POWER,
          this.updateInfinitePower,
          this
        ),
          b.Event.off(h.default.ENTER_ID, this.sucEnterByMode, this),
          _.Platform.hideBanner();
      }),
      (k.prototype.updateInfinitePower = function (e) {
        this.dict.infinitePowerBtn.active = !e;
      }),
      (k.prototype.initView = function () {
        return y(this, void 0, void 0, function () {
          var t, n, o, i, r;
          return a(this, function (e) {
            switch (e.label) {
              case 0:
                return (
                  (t = S.User.get(p.UserData.LEVEL_LIST) || {}),
                  [4, v.Config.get(l.ConfigConst.THEME)]
                );
              case 1:
                for (
                  n = e.sent(),
                  S.User.setTempData(p.TempData.CURRENT_ALL_MODE, n),
                  o = 0;
                  o < n.length;
                  o++
                )
                  (i = n[o].theme), t[i] || (t[i] = 1);
                return (
                  S.User.set(p.UserData.LEVEL_LIST, t),
                  S.User.setTempData(p.TempData.POWER_TYPE, 1),
                  S.User.get(p.UserData.FIRST_DAY_DATE) ||
                  (console.log("测试啊啊啊"),
                    S.User.set(p.UserData.FIRST_DAY_DATE, new Date().getDate())),
                  (r = m.BMS.getKey("GM")),
                  (this.dict.cheats.active = !!r),
                  (r = m.BMS.getKey("ugc")),
                  // (this.dict.createBtn.active = !!r),
                  (r = m.BMS.getKey("WuxianTiLi")),
                  (this.dict.infinitePowerBtn.active = true),
                  3 <= S.User.get(p.UserData.INF_POWER_VIDEO_TIMES) &&
                  this.updateInfinitePower(!0),
                  g.Audio.playMusic(x.AudioConst.BGM_MAIN),
                  cc.game.emit("gamelog", "page001"),
                  [2]
                );
            }
          });
        });
      }),
      (k.prototype.initPlatformUI = function () {
        var e,
          t = _.Platform.getConfig();
        (t.fitUIType != d.FitUIType.TT && t.fitUIType != d.FitUIType.KS) ||
          ((this.dict.topBar.getComponent(cc.Widget).top = 70),
            this.dict.topBar.getComponent(cc.Widget).updateAlignment()),
          t.hasAgeTip &&
          ((this.dict.ageBtn.active = !0),
            (e = _.Platform.getConfig().ageTipType) == d.AgeTipType.AGE_12 &&
            (this.dict.ageBtn.getComponent(cc.Sprite).spriteFrame =
              this.ageSpriteFrame[e])),
          (this.dict.privacyBtn.active = !1),
          t.privacyPolicyType != d.PrivacyPolicyType.NO &&
          (this.dict.privacyBtn.active = !0),
          (this.dict.moreGameBtn.active = !1),
          t.hasMoreGame && (this.dict.moreGameBtn.active = !0),
          (this.dict.customerService.active = !1),
          t.hasCustomerService && (this.dict.customerService.active = !0),
          (this.dict.logo.getComponent(cc.Sprite).spriteFrame =
            this.logoSpriteFrame[t.logoType]),
          _.Platform.is(d.EPlatform.OHAYOO_ANDROID) &&
          (this.dict.privacyBtn.children[0].getComponent(cc.Label).string =
            "隐私\n设置"),
          _.Platform.is(d.EPlatform.QQ) && (this.dict.appointBtn.active = !0);
      }),
      (k.prototype.clickSet = function () {
        cc.game.emit("gamelog", "btn004"), w.Popup.show(u.PopupConst.SET);
      }),
      (k.prototype.clickStart = function () {
        var t, n;
        this.isStart ||
          ((this.isStart = !0),
            cc.game.emit("gamelog", "btn001"),
            S.User.setTempData(p.TempData.CURRENT_MODE, 0),
            (t = S.User.get(p.UserData.LEVEL_LIST)),
            M.ConfigUtils.setNextModeID(),
            (n = 1),
            M.ConfigUtils.getDataByID(0, function (e) {
              console.log("res - ", e),
                (n = e.amount),
                t[0] > n
                  ? S.User.setTempData(p.TempData.CURRENT_LEVEL, 1)
                  : S.User.setTempData(p.TempData.CURRENT_LEVEL, t[0]);
            }),
            window.__prv.doAction('点击按钮弹视频', ['hw']),
            C.Scene.loadScene(f.SceneConst.GAME));
        window.__prv && window.__prv.doAction(1, ['ks']);
      }),
      (k.prototype.clickInfinitePower = function () {
        window.__prv.doAction('点击按钮弹视频', ['hw']),
          cc.game.emit("gamelog", "btn007"),
          cc.game.emit("gamelog", "page011"),
          w.Popup.show(u.PopupConst.INFINITE_POWER);
      }),
      (k.prototype.clickHotMode = function () {
        cc.game.emit("gamelog", "btn002"),
          C.Scene.loadScene(f.SceneConst.MODE_SELECT, 1);
      }),
      (k.prototype.clickMoreMode = function () {
        cc.game.emit("gamelog", "btn003"),
          C.Scene.loadScene(f.SceneConst.MODE_SELECT, 2);
      }),
      (k.prototype.clickCheats = function () {
        (this.clickTimes += 1),
          console.log("[" + this.clickTimes + "]"),
          8 <= this.clickTimes &&
          (w.Popup.show(u.PopupConst.CHEATS), (this.clickTimes = 0));
      }),
      (k.prototype.clickAge = function () {
        w.Popup.show(u.PopupConst.AGE_TIP);
      }),
      (k.prototype.clickPrivacy = function () {
        var n = this,
          e = _.Platform.getConfig();
        e.privacyPolicyType == d.PrivacyPolicyType.MINI_GAME ||
          e.privacyPolicyType == d.PrivacyPolicyType.MINI_GAME_VIVO
          ? this.isLoadPrivacy ||
          ((this.isLoadPrivacy = !0),
            cc.resources.load(u.PopupConst.PRIVACY_POLICY, function (e, t) {
              (n.isLoadPrivacy = !1),
                e
                  ? console.error(e)
                  : ((t = cc.instantiate(t)),
                    n.node.addChild(t),
                    t.getComponent("crtPrivacyWin").open());
            }))
          : e.privacyPolicyType == d.PrivacyPolicyType.NATIVE &&
          _.Platform.showPrivacyPolicy();
      }),
      (k.prototype.clickAppoint = function () {
        var n = this;
        this.isLoadPrivacy ||
          ((this.isLoadPrivacy = !0),
            cc.resources.load(u.PopupConst.PRIVACY_POLICY, function (e, t) {
              (n.isLoadPrivacy = !1),
                e
                  ? console.error(e)
                  : ((t = cc.instantiate(t)),
                    n.node.addChild(t),
                    t.getComponent("PrivacyPolicy").openUserPanelHandle());
            }));
      }),
      (k.prototype.clickMoreGame = function () {
        _.Platform.showMoreGame();
      }),
      (k.prototype.clickLevelSelect = function () {
        cc.game.emit("gamelog", "page002"),
          S.User.setTempData(p.TempData.CURRENT_MODE, 0),
          C.Scene.loadScene(f.SceneConst.LEVEL_SELECT);
      }),
      (k.prototype.clickCreateBtn = function () {
        window.__prv.doAction('点击按钮弹视频', ['hw']),
          cc.game.emit("gamelog", "btn027"),
          !m.BMS.getKey("ugcad") || S.User.get(p.UserData.isUnlockUgc)
            ? this.isEnterUgc ||
            ((this.isEnterUgc = !0), C.Scene.loadScene(f.SceneConst.UGC))
            : w.Popup.show(u.PopupConst.UNLOCK_UGC);
      }),
      (k.prototype.clickLoveDog = function () {
        window.__prv.doAction('点击按钮弹视频', ['hw']),
          cc.game.emit("gamelog", "btn028"), this.enterByMode(1);
        window.__prv.doAction(1, ['ks']);
      }),
      (k.prototype.clickDogStone = function () {
        window.__prv.doAction('点击按钮弹视频', ['hw']),
          cc.game.emit("gamelog", "btn029"), this.enterByMode(2);
        window.__prv.doAction(1, ['ks']);
      }),
      (k.prototype.enterByMode = function (e) {
        if (
          m.BMS.getKey("newmodead") &&
          -1 == (S.User.get(p.UserData.UNLOCK_MODE_LIST) || []).indexOf(e)
        )
          return (
            S.User.setTempData(p.TempData.CURRENT_MODE_UNLOCK_ID, e),
            void w.Popup.show(u.PopupConst.MODE_UNLOCK)
          );
        this.sucEnterByMode(e);
      }),
      (k.prototype.sucEnterByMode = function (t) {
        S.User.setTempData(p.TempData.CURRENT_MODE, t);
        var n = S.User.get(p.UserData.LEVEL_LIST);
        M.ConfigUtils.setNextModeID();
        var o;
        M.ConfigUtils.getDataByID(t, function (e) {
          (o = e.amount),
            n[t] > o
              ? S.User.setTempData(p.TempData.CURRENT_LEVEL, 1)
              : S.User.setTempData(p.TempData.CURRENT_LEVEL, n[t]);
        }),
          C.Scene.loadScene(f.SceneConst.GAME);
      }),
      r([t([cc.SpriteFrame])], k.prototype, "ageSpriteFrame", void 0),
      r([t([cc.SpriteFrame])], k.prototype, "logoSpriteFrame", void 0),
      r([e], k));
function k() {
  var e = (null !== s && s.apply(this, arguments)) || this;
  return (
    (e.clickTimes = 0),
    (e.ageSpriteFrame = []),
    (e.logoSpriteFrame = []),
    (e.isStart = !1),
    (e.isLoadPrivacy = !1),
    (e.isEnterUgc = !1),
    e
  );
}
n.default = e;
